import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'dart:developer' as developer;

///
///  开关控件 控件
///  https://api.flutter-io.cn/flutter/widgets/Image-class.html
///
///
///
///   Switch  开关
///   https://api.flutter-io.cn/flutter/material/Switch-class.html
///
///
///   check  复选框
///   https://api.flutter-io.cn/flutter/material/Checkbox-class.html
///
///
///
///   Radio 单选按钮
///  https://api.flutter-io.cn/flutter/material/Radio-class.html
///
///
///
///   Slider 滑动选择器
///   https://api.flutter-io.cn/flutter/material/Slider-class.html
///
///
///

class CheckPage extends StatefulWidget{
  @override
  State<CheckPage> createState() => CheckPageState();

}

class CheckPageState extends State<CheckPage>{

  bool _switchSelected = false;

  bool _checkSelected = false;



  SingingCharacter? _character = SingingCharacter.one;


  double _currentSliderValue = 20 ;

  bool _switchIosSelected = false;

  @override
  Widget build(BuildContext context) {


    return  Scaffold(
      appBar: AppBar(
        title: Text("开关组件使用"),
      ),
      body: ListView(
        children: [
          Padding(padding: EdgeInsets.all(8.0),
          child:Switch(
            value: _switchSelected,
            onChanged: (value){
              setState(() {
                _switchSelected = value;
              });
              developer.log("switch 状态：$_switchSelected");
            },
            //选中的颜色
            activeColor: Colors.red,
            //未选中的颜色
            inactiveThumbColor: Colors.black45,
          ),),
          Padding(padding: EdgeInsets.all(8.0),
            child:Checkbox(
              value: _checkSelected,
              checkColor: Colors.red,
              fillColor:MaterialStateProperty.all(Colors.lightGreen),
              onChanged: (bool? value) {
                setState(() {
                  _checkSelected = value!;
                });
                developer.log("Checkbox 状态：$_checkSelected");
              },
            ),),

          // radio
          ListTile(
            title: const Text("第一"),
            leading: Radio<SingingCharacter>(
              value: SingingCharacter.one,
              groupValue: _character,
              onChanged: (SingingCharacter? value){
                setState(() {
                  _character = value;
                });
              },
            ),
          ),
          ListTile(
            title: const Text("第二"),
            leading: Radio<SingingCharacter>(
              value: SingingCharacter.two,
              groupValue: _character,
              onChanged: (SingingCharacter? value){
                setState(() {
                  _character = value;
                });
              },
            ),
          ),
          RadioListTile<SingingCharacter>(
            title: const Text("第三"),
              value: SingingCharacter.three,
              groupValue: _character,
              onChanged: (SingingCharacter? value){
                setState(() {
                  _character = value;
                });
              },
          ),
          SizedBox(
            height: 40,
          ),
          Slider(value: _currentSliderValue, onChanged: (double value){
            setState(() {
              _currentSliderValue = value;
            });
          },
          max: 100, min: 0,
            divisions: 10,
            activeColor: Colors.green,
            inactiveColor: Colors.black45,
          ),
          //ios风格相关控件

          CupertinoSwitch(
            value: _switchIosSelected,
            activeColor: CupertinoColors.activeBlue,
            onChanged: (bool? value){
                setState(() {
                    _switchIosSelected = value ?? false;
                });
            },
          )




        ],
      ),

    );
  }


}




enum SingingCharacter {
  one, two,three
}